﻿using System;
using System.Windows;
using KaxamlPlugins;
using Oxage.Common;
using Oxage.Printing;

namespace Kaxaml.Plugins.Printing
{
	public partial class KaxamlContractService : IContractService
	{
		#region Constructor
		public KaxamlContractService()
		{
			KaxamlInfo.Frame.ContentRendered += (sender, e) =>
			{
				OnDocumentChanged();
			};
		}
		#endregion

		#region IContractService Members
		public FrameworkElement DocumentContent
		{
			get
			{
				return KaxamlInfo.Frame.Content as FrameworkElement;
			}
		}

		public string DocumentPath
		{
			get
			{
				//TODO: Get xaml path
				return null;
			}
		}

		public void WriteLine(string message)
		{
			OnDebugMessage(message);
		}

		public ProjectTypes ProjectType
		{
			get { return ProjectTypes.WPF; }
		}

		public event EventHandler<EventArgs<string>> DebugMessage;
		protected virtual void OnDebugMessage(string message)
		{
			if (DebugMessage != null)
			{
				DebugMessage(this, new EventArgs<string>(message));
			}
		}

		public event EventHandler DocumentChanged;
		protected virtual void OnDocumentChanged()
		{
			if (DocumentChanged != null)
			{
				DocumentChanged(this, new EventArgs());
			}
		}
		#endregion
	}
}
